﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcTemplates.Client.Models;
using MvcTemplates.Model;

namespace MvcTemplates.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            ViewBag.Message = "Welcome to ASP.NET MVC!";
            ViewBag.Stuff = "test";

            var vm = new ViewModel();
            ViewData["SelectListItemsViewDataKey"] = new SelectList( new[] {"thing1", "thing2"} );
            return View(vm);
        }

        public ActionResult About()
        {
            return View();
        }

        public class BirdsViewModel
        {
            [DropDown("birds")]
            public string Bird { get; set; }
        }

        public ActionResult DropDownFromViewDataExample()
        {
            ViewData["birds"] = new SelectList( new[] {"blue jay", "robin"} );
            var model = new BirdsViewModel();
            return View( model );
        }

        private class AutoCompleteResult
        {
            public AutoCompleteResult( string id, string label )
            {
                this.id = id;
                this.label = label;
                this.value = id;
            }

            public string id { get; set; }
            public string label { get; set; }
            public string value { get; set; }
        }

        public ActionResult Autocomplete( string term )
        {
            var data = new List<AutoCompleteResult>
                           {
                               new AutoCompleteResult( "Link A", "Link A (/page1)" ),
                               new AutoCompleteResult( "Link B", "Link B (/page2)" )
                           };
            return Json( data.Where( x => x.label.Contains( term ) ), JsonRequestBehavior.AllowGet );
        }

        public dynamic UserRepository { get; set; }
        public dynamic CityRepository { get; set; }

public class EditMaritalStatusViewModel
{
    [Required]
    public RadioButtonList MaritalStatus { get; set; }
}

[HttpGet]
public ActionResult EditMaritalStatus()
{
    var maritalStatusRadioButtonList = new RadioButtonList()
                        {
                            Value = "Single",
                            Options = new SelectList( new[]{ "Single", "Married", "Divorced" } )
                        };
    var viewModel = new EditMaritalStatusViewModel
                        {
                            MaritalStatus = maritalStatusRadioButtonList
                        };
    return View( viewModel );
}

[HttpPost]
public ActionResult EditMaritalStatus( EditMaritalStatusViewModel model )
{
    var selectedValue = model.MaritalStatus.Value;
            
    //do something with the selected value
            
    return RedirectToAction( "EditMaritalStatus" );
}
    }
}
